package com.zxn.ssyx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zxn.ssyx.mapper.AttrGroupMapper;
import com.zxn.ssyx.model.product.AttrGroup;
import com.zxn.ssyx.service.AttrGroupService;
import com.zxn.ssyx.vo.product.AttrGroupQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AttrGroupServiceImpl extends ServiceImpl<AttrGroupMapper, AttrGroup> implements AttrGroupService {
    @Autowired
    private AttrGroupMapper attrGroupMapper;

    @Override
    public IPage<AttrGroup> selectPage(Page<AttrGroup> pageParam, AttrGroupQueryVo attrGroupQueryVo) {
        LambdaQueryWrapper<AttrGroup> lqw = new LambdaQueryWrapper<>();
        if (attrGroupQueryVo.getName() != null) {
            lqw.like(AttrGroup::getName, attrGroupQueryVo.getName());
        }
        return attrGroupMapper.selectPage(pageParam, lqw);
    }

    @Override
    public List<AttrGroup> findAllList() {
        LambdaQueryWrapper<AttrGroup> lqw = new LambdaQueryWrapper<>();
        lqw.orderByAsc(AttrGroup::getSort);
        return attrGroupMapper.selectList(lqw);
    }
}
